#include <types.h>
#include <osal/osal.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <api/libosd/osd_lib.h>
#include <api/libttx/lib_ttx.h>
#include <api/libsubt/lib_subt.h>

#include "copper_common/system_data.h"
#include "copper_common/com_api.h"

#include "osdobjs_def.h"
#include "win_com_menu_define.h"
#include "win_com_popup.h"
#include "menus_root.h"

#include "osd_config.h"
#include "string.id"
#include "images.id"
#include <api/libmp/mp_subtitle_api.h>

#include "win_subtitle.h"
#include "win_com.h"

#define SUBTITLE_ITEM_NUMBER 5
UINT16	Subtitle_track_idx[SUBTITLE_ITEM_NUMBER][5];
UINT16	Subtitle_track_str[SUBTITLE_ITEM_NUMBER][24];


UINT16* p_subtitle_track_str[SUBTITLE_ITEM_NUMBER];
UINT16* p_subtitle_track_idx[SUBTITLE_ITEM_NUMBER];
UINT8 g_win_subtitle_count;
UINT8 g_win_ttx_subtitle_count;
extern UINT8 cur_tuner_idx;
extern struct nim_device  *g_nim_dev,*g_nim_dev2;

LISTFIELD list_field_subtitle[] = 
{
	{80,4,4,0,0,C_ALIGN_LEFT|C_ALIGN_VCENTER,FIELD_IS_TEXT,p_subtitle_track_idx},
	{SUBTITLE_LS_W-80,0,4,0,0,C_ALIGN_LEFT|C_ALIGN_VCENTER,FIELD_IS_TEXT,p_subtitle_track_str},
};
/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER	g_cnt_subtitle;
extern TEXT_FIELD	g_txt_subtitle;
extern LIST		g_ls_subtitle;
extern SCROLL_BAR	g_sb_subtitle;

void win_com_set_idx_str(UINT16 idx, UINT16 * str, UINT16 len);
static VACTION subtile_con_keymap(POBJECT_HEAD obj, UINT32 key);
static PRESULT subtitle_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT subtitle_list_callback(POBJECT_HEAD obj, VEVENT event, UINT32 param1, UINT32 param2);
static VACTION win_sub_list_keymap(POBJECT_HEAD obj, UINT32 key);

struct t_ttx_lang* ttx_sub_lang_list;
struct t_subt_lang* sub_lang_list;

//object define
CONTAINER    g_cnt_subtitle={
	{	OT_CONTAINER, //object type
		C_ATTR_ACTIVE,   // defined in form C_ATTR_XXX
		C_FONT_DEFAULT,    // defined in form C_FONT_XXX
		0,      // 0: for component without focus

		0,//UINT8 bLeftID;
		0,//UINT8 bRightID;
		0,//UINT8 bUpID;
		0,//UINT8 bDownID;

		{SUBTITLE_L, SUBTITLE_T, SUBTITLE_W, SUBTITLE_H},//OSD_RECT frame;
		{WSTL_WIN_SLIST_02_8BIT, WSTL_WIN_SLIST_02_8BIT, WSTL_WIN_SLIST_02_8BIT, WSTL_WIN_SLIST_02_8BIT},//COLOR_STYLE style;

		subtile_con_keymap,//PFN_KEY_MAP pfnKeyMap;
		subtitle_con_callback,//PFN_CALLBACK pfnCallback;

		NULL,//POBJECT_HEAD pNext;
		NULL//POBJECT_HEAD pRoot;
	},
	(POBJECT_HEAD)&g_txt_subtitle,
	1,//focus
	0
};

TEXT_FIELD	g_txt_subtitle = {
	{	OT_TEXTFIELD, //object type
		C_ATTR_ACTIVE,   // defined in form C_ATTR_XXX
		C_FONT_DEFAULT,    // defined in form C_FONT_XXX
		0,      // 0: for component without focus

		0,//UINT8 bLeftID;
		0,//UINT8 bRightID;
		0,//UINT8 bUpID;
		0,//UINT8 bDownID;

		{SUBTITLE_TXT_L, SUBTITLE_TXT_T, SUBTITLE_TXT_W, SUBTITLE_TXT_H},//OSD_RECT frame;
		{WSTL_MIXBACK_IDX_04_8BIT, WSTL_MIXBACK_IDX_04_8BIT, WSTL_MIXBACK_IDX_04_8BIT, 0},//COLOR_STYLE style;

		NULL,//PFN_KEY_MAP pfnKeyMap;
		NULL,//PFN_CALLBACK pfnCallback;

		(POBJECT_HEAD)&g_ls_subtitle,//POBJECT_HEAD pNext;
		(POBJECT_HEAD)&g_cnt_subtitle,//POBJECT_HEAD pRoot;
	},
	C_ALIGN_CENTER | C_ALIGN_VCENTER,//    UINT8 bAlign;
	0,//UINT8 bX;
	0,//UINT8 bY;
	RS_SYSTEM_LANGUAGE_SUBTITLE_LANGUAGE,//UINT16 wStringID;  // string id
	NULL,//UINT16* pString;   // unicode string pointer
};

#define LDEF_SET_LIST(root, varCon,nxtObj,l,t,w,h,field,numfield,page,bar,intervaly,keymap,callback)		\
	DEF_LIST(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
	1,1,1,1,1,l,t,w,h, LIST_SH_IDX,LIST_HL_IDX,LIST_SL_IDX,LIST_GRY_IDX,\
	keymap,callback,LIST_FULL_PAGE| LIST_PAGE_KEEP_CURITEM|LIST_GRID|LIST_SCROLL,\
	field,numfield,page,(SCROLL_BAR* )bar,intervaly,NULL,0/*cnt*/,0/*ntop*/,0/*nsel*/,0/*npos*/)
#define LDEF_LISTBAR(root,varScb,page,l,t,w,h)	\
	DEF_SCROLLBAR(varScb,root, NULL, C_ATTR_ACTIVE, 0, \
		0, 0, 0, 0, 0, l, t, w, h, LIST_BAR_SH_IDX, LIST_BAR_HL_IDX, LIST_BAR_SH_IDX, LIST_BAR_SH_IDX, \
		NULL, NULL, BAR_VERT_AUTO | SBAR_STYLE_RECT_STYLE, page, LIST_BAR_MID_THUMB_IDX, LIST_BAR_MID_RECT_IDX, \
		0, 10, w, h - 20, 100, 1)

LDEF_SET_LIST(&g_cnt_subtitle,g_ls_subtitle,&g_sb_subtitle, \
				SUBTITLE_LS_L, SUBTITLE_LS_T, SUBTITLE_LS_W, SUBTITLE_LS_H,\
				list_field_subtitle,2,SUBTITLE_LS_PAGE,&g_sb_subtitle,0,\
				win_sub_list_keymap,subtitle_list_callback);
LDEF_LISTBAR(&g_cnt_subtitle,g_sb_subtitle,\
				SUBTITLE_LS_PAGE,SUBTITLE_SB_L, SUBTITLE_SB_T, SUBTITLE_SB_W, SUBTITLE_SB_H);

void win_subtitle_read_page(UINT8 top)
{
	UINT8 i,ttx_idx,subt_idx;
	struct t_subt_lang* p_lang;
	struct t_ttx_lang* p_ttx_lang;
	p_lang = sub_lang_list;
	p_ttx_lang = ttx_sub_lang_list;

	if(top > (g_win_ttx_subtitle_count + g_win_subtitle_count + 1))
	{
		top = 0;/*if top value overflow,set it to zero*/
		OSD_SetListCurPos(&g_ls_subtitle,0);
		OSD_SetListTop(&g_ls_subtitle,0);
	}
	
	for(i = 0;i < SUBTITLE_ITEM_NUMBER;i++)
	{
		if((top+i) < g_win_ttx_subtitle_count)
		{
			ttx_idx = (top + i);
			p_ttx_lang = (ttx_sub_lang_list + ttx_idx);
			
			Subtitle_track_str[i][0]=p_ttx_lang->lang[0];
			Subtitle_track_str[i][1]=p_ttx_lang->lang[1];
			Subtitle_track_str[i][2]=p_ttx_lang->lang[2];
			Subtitle_track_str[i][3]='(';
			Subtitle_track_str[i][4]='T';
			Subtitle_track_str[i][5]=')';
            if(p_lang->subt_type < 0x20)   
			    Subtitle_track_str[i][6]=0;
            else {
			    Subtitle_track_str[i][6]=' ';
			    Subtitle_track_str[i][7]='h';
			    Subtitle_track_str[i][8]='e';
			    Subtitle_track_str[i][9]='a';
			    Subtitle_track_str[i][10]='r';
			    Subtitle_track_str[i][11]='i';
			    Subtitle_track_str[i][12]='n';
			    Subtitle_track_str[i][13]='g';
			    Subtitle_track_str[i][14]=' ';
			    Subtitle_track_str[i][15]='i';
			    Subtitle_track_str[i][16]='m';
			    Subtitle_track_str[i][17]='p';
			    Subtitle_track_str[i][18]='a';
			    Subtitle_track_str[i][19]='i';
			    Subtitle_track_str[i][20]='r';
			    Subtitle_track_str[i][21]='e';
			    Subtitle_track_str[i][22]='d';
			    Subtitle_track_str[i][23]=0;
            }
			ComUniStrToMB(Subtitle_track_str[i]);
			
			win_com_set_idx_str(top+i, Subtitle_track_idx[i],2);
		}		
		else if((top+i) < (g_win_ttx_subtitle_count + g_win_subtitle_count))
		{
			subt_idx = (top + i - g_win_ttx_subtitle_count);
			p_lang = (sub_lang_list + subt_idx);
			
			Subtitle_track_str[i][0]=p_lang->lang[0];
			Subtitle_track_str[i][1]=p_lang->lang[1];
			Subtitle_track_str[i][2]=p_lang->lang[2];
			Subtitle_track_str[i][3]='(';
			Subtitle_track_str[i][4]='D';
			Subtitle_track_str[i][5]=')';
            if(p_lang->subt_type < 0x20)   
			    Subtitle_track_str[i][6]=0;
            else {
			    Subtitle_track_str[i][6]=' ';
			    Subtitle_track_str[i][7]='h';
			    Subtitle_track_str[i][8]='e';
			    Subtitle_track_str[i][9]='a';
			    Subtitle_track_str[i][10]='r';
			    Subtitle_track_str[i][11]='i';
			    Subtitle_track_str[i][12]='n';
			    Subtitle_track_str[i][13]='g';
			    Subtitle_track_str[i][14]=' ';
			    Subtitle_track_str[i][15]='i';
			    Subtitle_track_str[i][16]='m';
			    Subtitle_track_str[i][17]='p';
			    Subtitle_track_str[i][18]='a';
			    Subtitle_track_str[i][19]='i';
			    Subtitle_track_str[i][20]='r';
			    Subtitle_track_str[i][21]='e';
			    Subtitle_track_str[i][22]='d';
			    Subtitle_track_str[i][23]=0;
            }
			ComUniStrToMB(Subtitle_track_str[i]);
			
			win_com_set_idx_str(top+i, Subtitle_track_idx[i],2);
		}
		else if((top+i) == (g_win_ttx_subtitle_count + g_win_subtitle_count))
		{
			Subtitle_track_str[i][0]='O';
			Subtitle_track_str[i][1]='F';
			Subtitle_track_str[i][2]='F';
			Subtitle_track_str[i][3]=0;
			ComUniStrToMB(Subtitle_track_str[i]);
			Subtitle_track_idx[i][0]=0;
		}
		else
		{
			Subtitle_track_idx[i][0]=0;
			Subtitle_track_str[i][0]=0;
		}
	}
}

void win_subtitle_init_data()
{
	P_NODE	p_node;
	UINT16 lst_top,list_cnt;
	UINT8 sel_lang = 0xFF;
	SYSTEM_DATA* sys_data = sys_data_get();
	
	TTXEng_GetSubtLang(&ttx_sub_lang_list, &g_win_ttx_subtitle_count);
	subt_get_language(&sub_lang_list, &g_win_subtitle_count);
	
	list_cnt =  (g_win_subtitle_count + g_win_ttx_subtitle_count + 1);
	OSD_SetListCount(&g_ls_subtitle, list_cnt);
	
	
	if(sys_data->osd_set.subtitle_display == 0)/*subtitle off,select the last item*/
	{
		OSD_SetListCurPos(&g_ls_subtitle, (list_cnt - 1));
		if(list_cnt > SUBTITLE_ITEM_NUMBER)
			OSD_SetListTop(&g_ls_subtitle, (list_cnt - SUBTITLE_ITEM_NUMBER));
		else
			OSD_SetListTop(&g_ls_subtitle, 0);
	}
	else if(sys_data->osd_set.subtitle_lang == 0xFF)/*set_sub_lang_idx can only be set in subtitle pop-up*/
	{/*if first init,or reset*/
		sel_lang = 0xFF;
#if (SUBTITLE_ON == 1)
		sel_lang = api_ttxsub_getlang(NULL,sub_lang_list,sys_data->lang.sub_lang,g_win_subtitle_count);
		if(sel_lang != 0xFF)
		{
			sel_lang = sel_lang + g_win_ttx_subtitle_count;
		}/*subtitle language select first*/
#endif

#if (TTX_ON ==1)			
		if(sel_lang == 0xFF)
		{	
			sel_lang = api_ttxsub_getlang(ttx_sub_lang_list,NULL,sys_data->lang.sub_lang,g_win_ttx_subtitle_count);				
		}/*if can not get subt lang_idx,to get ttx_subt lang_idx*/
#endif
		if(sel_lang != 0xFF)/*If sel_lang valid,set to corresponding item highlight*/
		{
			OSD_SetListCurPoint(&g_ls_subtitle, sel_lang);
			//OSD_SetListTopPoint(&g_ls_subtitle, sel_lang);
			if(sel_lang > (SUBTITLE_ITEM_NUMBER - 1))
				OSD_SetListTop(&g_ls_subtitle, (sel_lang - SUBTITLE_ITEM_NUMBER + 1));
			else
				OSD_SetListTop(&g_ls_subtitle, 0);
		}
		else/*if sel_lang invalid,set to 0 position*/
		{
			OSD_SetListCurPoint(&g_ls_subtitle, 0);
			OSD_SetListTopPoint(&g_ls_subtitle, 0);
		}
	}
	else
	{
		OSD_SetListCurPoint(&g_ls_subtitle, sys_data->osd_set.subtitle_lang); 
	        if(sys_data->osd_set.subtitle_lang > (SUBTITLE_ITEM_NUMBER - 1))
			OSD_SetListTop(&g_ls_subtitle, (sys_data->osd_set.subtitle_lang - SUBTITLE_ITEM_NUMBER + 1));
		else
			OSD_SetListTop(&g_ls_subtitle, 0);
	}

	OSD_SetListVerScrollBar(&g_ls_subtitle, &g_sb_subtitle);
	
	lst_top = OSD_GetListTopPoint(&g_ls_subtitle);
	win_subtitle_read_page(lst_top);
}

#ifdef MP_SUBTITLE_SUPPORT	//vic100507#1

extern void* subtitle_handle;
extern EXT_SUB_PLUGIN *g_ext_subtitle_plugin;

long win_mp_subtitle_read_page(UINT8 top)
{
	long			i, j;
	long			ret = -1;
	long			number;
	long			current_language_index;
	char			description[201] = {0};
	long			description_len;
	char			*temp;

	if (!subtitle_handle)
	{
		return -1;
	}

	number = 0;
	description_len = 200;

	if(g_ext_subtitle_plugin)
		ret = g_ext_subtitle_plugin->mps_query_language(subtitle_handle, &number, &current_language_index, description, &description_len);
	
	if (ret < 0)
	{
		return -1;
	}


	if(top > number)
	{
		top = 0;
		OSD_SetListCurPos(&g_ls_subtitle,0);
		OSD_SetListTop(&g_ls_subtitle,0);
	}
	
	for(i = 0;i < SUBTITLE_ITEM_NUMBER;i++)
	{
		if((top+i) < number)
		{
			temp = description + (top+i)*4;
			
			Subtitle_track_str[i][0]=temp[0];
			Subtitle_track_str[i][1]=temp[1];
			Subtitle_track_str[i][2]=temp[2];
			Subtitle_track_str[i][3]=0;
			Subtitle_track_str[i][4]=0;
			Subtitle_track_str[i][5]=0;
			Subtitle_track_str[i][6]=0;
			ComUniStrToMB(Subtitle_track_str[i]);
			
			win_com_set_idx_str(top+i, Subtitle_track_idx[i], 2);
		}		
		else
		{
			Subtitle_track_idx[i][0]=0;
			Subtitle_track_str[i][0]=0;
		}
	}

	return 1;
}


long win_mp_subtitle_init_data()
{
	long			ret = -1;
	long			number;
	long			current_language_index;
	UINT16 lst_top,list_cnt;
	UINT8 sel_lang = 0xFF;

	if (!subtitle_handle)
	{
		return -1;
	}

	if(g_ext_subtitle_plugin)
		ret = g_ext_subtitle_plugin->mps_query_language(subtitle_handle, &number, &current_language_index, NULL, NULL);
	
	if (ret < 0)
	{
		return -1;
	}
	
	list_cnt =  number;
	OSD_SetListCount(&g_ls_subtitle, list_cnt);


	OSD_SetListCurPos(&g_ls_subtitle, current_language_index);
	OSD_SetListTop(&g_ls_subtitle, current_language_index);
	
	OSD_SetListVerScrollBar(&g_ls_subtitle, &g_sb_subtitle);
	
	lst_top = OSD_GetListTopPoint(&g_ls_subtitle);
	ret = win_mp_subtitle_read_page(lst_top);
	return ret;
}
#endif


VACTION subtile_con_keymap(POBJECT_HEAD obj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
		case V_KEY_EXIT:
		case V_KEY_MENU:
		case V_KEY_SUBTITLE:
			act = VACT_CLOSE;
			break;		
		case V_KEY_ENTER:
			act = VACT_ENTER;
			break;		
		default:	
			act = OSD_ContainerKeyMap(obj,key);
	}

	return act;
}

static PRESULT subtitle_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	SYSTEM_DATA * sys;
	struct nim_device* nim_dev;	
	UINT8 i,lock;
	UINT8 unact;
	
	if(cur_tuner_idx == 0)
		nim_dev = g_nim_dev;
	else
		nim_dev = g_nim_dev2;
#if defined SAT2IP_SERVER_SUPPORT || defined SAT2IP_CLIENT_SUPPORT
	if (api_cur_prog_is_sat2ip())
		nim_dev = NULL;
#endif
    nim_get_lock(nim_dev,&lock);

	switch(event)
	{
	case EVN_PRE_OPEN:
        #ifdef SUPPORT_CAS9
			if(0==get_mmi_showed())
				ShowSignalStatusOSDOnOff(0);
        #endif
        api_set_deo_layer(0);
        api_inc_wnd_count();

		for(i=0;i<SUBTITLE_ITEM_NUMBER;i++)
		{
			p_subtitle_track_str[i]=Subtitle_track_str[i];
			p_subtitle_track_idx[i]=Subtitle_track_idx[i];
		}

		if(system_state != SYS_STATE_USB_MP)//vic100507#1	
		{
			win_subtitle_init_data();
			if(((0 == g_win_subtitle_count ) && (0 == g_win_ttx_subtitle_count)) || (!lock))
			#if (DVR_PVR_SUPPORT_SUBTITLE)//temp disable
			if(((0 == g_win_subtitle_count ) && (0 == g_win_ttx_subtitle_count)) 
			#ifdef DVR_PVR_SUPPORT
				|| ((!lock) && !api_pvr_is_playing())
			#else
				|| (!lock)
			#endif
				)
			#endif
			{
				#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
					UINT8 back_saved;
					win_compopup_init(WIN_POPUP_TYPE_SMSG);
					win_compopup_set_msg_ext(NULL, NULL, RS_DISPLAY_NO_DATA);
					win_compopup_open_ext(&back_saved);	
					osal_task_sleep(1000);
					win_compopup_smsg_restoreback();
				#else
				win_com_popup_open(WIN_POPUP_TYPE_SMSG,NULL, RS_DISPLAY_NO_DATA);			
				osal_task_sleep(1000);
				win_compopup_close();
				#endif
	            api_dec_wnd_count();
				return PROC_LEAVE;
			}
		}
		else
		{
		#ifdef MP_SUBTITLE_SUPPORT	//vic100507#1			
			//TODO:
			//such like win_subtitle_init_data
			long resut;
			resut = win_mp_subtitle_init_data();
			if (resut < 0)
			{						
				return PROC_LEAVE;				
			}
			
		#endif				
		}
		break;		
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);

		if(system_state != SYS_STATE_USB_MP)//vic100507#1 
		{

			if(VACT_ENTER == unact)
			{
				UINT16	cur_sel = OSD_GetListCurPoint(&g_ls_subtitle);
				sys = sys_data_get();
				if(g_win_subtitle_count + g_win_ttx_subtitle_count==cur_sel)
				{
					sys->osd_set.subtitle_display = 0;/*select off option*/
					sys->osd_set.subtitle_lang = 0xFF;
				}
				else if(cur_sel < g_win_ttx_subtitle_count)
				{
					sys->osd_set.subtitle_lang = cur_sel;/*set_sub_lang_idx is used in api_osd_mode_change function*/
#if(AOV_TTC_SUBTITLE_SUPPORT_ENABLE == SYS_FUNC_OFF)
					sys->osd_set.subtitle_display = 1;/*subtitle on*/
					sys_data_select_Subtitle_language(sys->osd_set.subtitle_lang);//Martin@20150107_subtitle
#endif					
				}
				else if(cur_sel < g_win_subtitle_count + g_win_ttx_subtitle_count)
				{/*ttx_subtitle on the top then normal subtitle*/
					sys->osd_set.subtitle_lang = cur_sel;/*set_sub_lang_idx is used in api_osd_mode_change function*/
#if(AOV_TTC_SUBTITLE_SUPPORT_ENABLE == SYS_FUNC_OFF)
					sys->osd_set.subtitle_display = 1;/*subtitle on*/						
					sys_data_select_Subtitle_language(sys->osd_set.subtitle_lang);//Martin@20150107_subtitle
#endif	
				}
				ret = PROC_LEAVE;
				api_osd_mode_change(OSD_NO_SHOW);
				sys_data_save(0);
#if(AOV_TTC_SUBTITLE_SUPPORT_ENABLE == SYS_FUNC_ON)
				AOV_TCC_Subtitle_language();
#endif				
				//api_osd_mode_change(OSD_SUBTITLE);
			}
		}
		else if(VACT_ENTER == unact)
		{
		//vic100507#1 begin
		#ifdef MP_SUBTITLE_SUPPORT	
			//TODO:
			//select language index
			if (!subtitle_handle)
			{
				return PROC_LEAVE;
			}
			long resut;
			UINT16	cur_sel = OSD_GetListCurPoint(&g_ls_subtitle);

			if(g_ext_subtitle_plugin)
				g_ext_subtitle_plugin->mps_change_language(subtitle_handle,cur_sel);
			
			OSD_ObjClose(pObj,C_CLOSE_CLRBACK_FLG);
			//if (resut < 0)
			{
				return PROC_LEAVE;
			}			
		#endif					
		//vic100507#1 end
		}
		break;

	case EVN_MSG_GOT:
#ifdef USB_MP_SUPPORT
		if(param1 == CTRL_MSG_SUBTYPE_STATUS_VIDEO_OVER)
		{
			ret = PROC_LEAVE;
			ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_VIDEO_OVER,0,TRUE);
		}
#endif
		break;
	
	case EVN_PRE_CLOSE:
		unact = (VACTION)(param1>>16);
		ret = PROC_PASS;
        break;

	case EVN_POST_CLOSE:
        #ifdef SUPPORT_CAS9
            restore_ca_msg_when_exit_win();
        #endif
        api_set_deo_layer(1);
        api_dec_wnd_count();
        break;
	default:
		break;
	}

	return ret;
}

 static VACTION win_sub_list_keymap(POBJECT_HEAD obj, UINT32 key)
{
	VACTION	act = VACT_PASS;

	switch(key)
	{
		case V_KEY_LEFT:
  			act = VACT_CURSOR_LEFT;
  			break;
  		case V_KEY_RIGHT:
  			act = VACT_CURSOR_RIGHT;
  			break;
		case V_KEY_ENTER:
			act = VACT_ENTER;
			break;
		default:
			act = OSD_ListKeyMap(obj, key);
	}
	
	return act;
}

static PRESULT subtitle_list_callback(POBJECT_HEAD obj, VEVENT event, UINT32 param1, UINT32 param2)
{
	UINT16 top, cnt, pos;
	UINT8 unact;
	PRESULT ret = PROC_PASS;

	switch(event)
	{
		case EVN_PRE_DRAW:
//vic100507#1			
			top = OSD_GetListTopPoint(&g_ls_subtitle);
			OSD_SetListTopPoint(&g_ls_subtitle, top);
			top= OSD_GetListTopPoint(&g_ls_subtitle);
			if(system_state != SYS_STATE_USB_MP)
				win_subtitle_read_page(top);
#ifdef MP_SUBTITLE_SUPPORT							
			else
				//TODO: set display items string
				win_mp_subtitle_read_page(top);
#endif
//vic100507#1				
			break;
		case EVN_REQUEST_DATA:
			top = (UINT16)param2;
			if(system_state != SYS_STATE_USB_MP)//vic100507#1
				win_subtitle_read_page(top);
#ifdef MP_SUBTITLE_SUPPORT	//vic100507#1						
			else
				//TODO: set display items string
				win_mp_subtitle_read_page(top);
#endif
			
			break;
		default:
			PRINTF("do nothing \n");
	}
	
	return ret;
}

void win_com_set_idx_str(UINT16 idx, UINT16 * str, UINT16 len)
{
	char tmp[11];
	char fmt[10];
	sprintf(fmt, "[%%.%dd]", len);
	sprintf(tmp, fmt, idx+1/*base on 1*/);
	ComAscStr2Uni(tmp, str);
}

